umsg.PoolString("Spin To")
AddCSLuaFile("autorun/client/roll.lua")

function RollPlayerSpawn(ply)
	ply.HasDoneARoll = false
end

hook.Add("PlayerSpawn", "RollPlayerSpawn", RollPlayerSpawn)

function PlayerLandsRoll(ply)
	if ply:EyeAngles().p >= 45 then
		if ply:KeyDown(IN_RELOAD) and ply:KeyDown(IN_DUCK) and ply:GetVelocityLength() <= 1100 then
			ply.HasDoneARoll = true
		end
	end
end

hook.Add("OnPlayerHitGround", "PlayerLandsRoll", PlayerLandsRoll)

function DoARoll(ent, inflictor, attacker, amount, dmginfo)
	if ent:IsPlayer() then
		if ent.HasDoneARoll == true then
			if (ent:Health() - (dmginfo:GetDamage() * 0.5)) > 0 then
				if dmginfo:IsFallDamage() then
					dmginfo:ScaleDamage(0.5)
					umsg.Start("Spin To", ent)
						umsg.Float(360)
						umsg.Float(1.8)
					umsg.End()
					ent.HasDoneARoll = false
				elseif ent:GetVelocity():Length() >= 1250 then
					return
				end
			end
		end
	end
end

hook.Add("EntityTakeDamage", "DoARoll", DoARoll)